package edu.study.common.util;

import javax.servlet.http.HttpServletRequest;

import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class HttpServletRequestUtil {
	
	public static HttpServletRequest getRequest() {
		HttpServletRequest request = null;
		RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
		if (requestAttributes != null) {
			request = ((ServletRequestAttributes)requestAttributes).getRequest();
		}
		return request;
	}
	
	public static Object getHead(String key) {
		if (StringUtils.isEmpty(key)) {
			return null;
		}
		HttpServletRequest request = getRequest();
		if (request == null) {
			return null;
		}
		return request.getHeader(key);
	}
}
